package org.jeecg.modules.payment;

import org.jeecg.cuckoo.enums.PaymentMethodEnum;
import org.jeecg.modules.payment.dto.PaymentRequest;
import org.jeecg.modules.payment.enums.CuDeviceTypeEnum;
import org.jeecg.modules.payment.enums.CuPaymentMethodEnum;
import org.jeecg.modules.payment.enums.CuPaymentPlatformEnum;
import org.jeecg.modules.payment.impl.PaymentBmwlImpl;
import org.jeecg.modules.payment.vo.PaymentResponse;

import java.math.BigDecimal;

/**
 * 支付工具类
 *
 * @author: wei
 * @date: 2024年08月06日 16:15
 */
public class PaymentUtil {

    private PaymentBase paymentBase;
    private CuPaymentPlatformEnum method;
    private String domainName = "http://pay.sichuangde.com";

    /**
     * 初始化选择支付工具
     * 'alipay', 'wechat', 'credit_card', 'bank_transfer'
     */
    public PaymentUtil(CuPaymentPlatformEnum method) {
        this.method = method;
        switch (method) {
            case BMWLPLAT:
                paymentBase = new PaymentBmwlImpl();
                break;
            default:
                break;
        }
    }

    /**
     * 生成支付订单
     *
     * @param outTradeNo   订单号
     * @param name         名称
     * @param money        金额
     * @param clientIp     用户ip
     * @param platformEnum 支付平台
     * @param device       设备类型
     * @return
     */
    public PaymentResponse createOrder(String outTradeNo, String name, BigDecimal money, String clientIp, String platformEnum, String device) {

        String notifyUrl = domainName + method.getNotifyUrl();
        PaymentRequest paymentRequest = new PaymentRequest();
        paymentRequest.setOutTradeNo(outTradeNo);
        paymentRequest.setName(name);
        paymentRequest.setMoney(money);
        paymentRequest.setType(platformEnum);
        paymentRequest.setDevice(device);
        paymentRequest.setNotifyUrl(notifyUrl);
        paymentRequest.setClientIp(clientIp);

        return paymentBase.createOrder(paymentRequest);
    }


}
